package com.content.view.Frame.MainPanel.MPHome
{
	import com.content.model.LoadedAssets.FontProxy;
	import com.content.model.LoadedAssets.SkinProxy;
	import com.content.model.OnlineRes.NoticeVO;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	import com.library.utils.TextFieldUtil;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFormatAlign;
	
	import gs.TweenLite;
	
	public class NoticeItem extends UIObject implements IDisposable
	{
		public static const HEIGHT:int = 22;
		
		private var _bg:Shape;
		private var _vo:NoticeVO;
		
		private var _txtAuthor:TextField;
		private var _txtTitle:TextField;
		private var _txtDate:TextField;
		
		private var _arr:Sprite;
		private var _arrActive:Sprite;
		
		public function NoticeItem(vo:NoticeVO)
		{
			super();
			
			mouseChildren = false;
			buttonMode = true;
			
			_vo = vo;
			
			_bg = new Shape();
			addChild(_bg);
			_bg.visible = false;
			
			_arr = new SkinProxy.ICO_Arrow() as Sprite;
			_arrActive = new SkinProxy.ICO_Arrow_Active() as Sprite;
			addChild(_arr);
			addChild(_arrActive);
			_arrActive.visible = false;
			
			_txtAuthor = TextFieldUtil.Generate("", 11, 0x000000, FontProxy.FONT_YAHEI);
			_txtTitle = TextFieldUtil.Generate("", 11, 0x000000, FontProxy.FONT_YAHEI, false, true, false, TextFormatAlign.LEFT, "", false);
			_txtDate = TextFieldUtil.Generate("", 11, 0x000000, FontProxy.FONT_YAHEI);
			
			_txtAuthor.height = HEIGHT;
			_txtTitle.height = HEIGHT;
			
			addChild(_txtAuthor);
			addChild(_txtTitle);
			addChild(_txtDate);
			
			_txtAuthor.text = vo.Author;
			_txtTitle.text = vo.Title;
			_txtDate.text = vo.Date;
			
			this.addEventListener(MouseEvent.MOUSE_OVER, OnOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, OnOut);
		}
		
		public function get VO():NoticeVO{	return _vo;	}
		
		public function SetLayout(areaWidth:int):void{
			_bg.graphics.clear();
			_bg.graphics.beginFill(0x3c6995, 1.0);
			_bg.graphics.drawRect(0,0,areaWidth, HEIGHT);
			
			_arr.y = _arrActive.y = 7;
			
			var arrW:int = int(_arr.width + 5);
			var txtAuthorW:int = 80;
			var txtDateW:int = 65;
			
			_txtAuthor.x = arrW;
			_txtAuthor.width = txtAuthorW;
			_txtTitle.x = arrW + txtAuthorW;
			var spareW:int = int(areaWidth - arrW - txtAuthorW - txtDateW);
			_txtTitle.width = spareW;
			_txtDate.x = areaWidth - txtDateW;
		}
		
		public function Dispose():void
		{
			_vo = null;
			this.removeEventListener(MouseEvent.MOUSE_OVER, OnOver);
			this.removeEventListener(MouseEvent.MOUSE_OUT, OnOut);
		}
		
		/* Event Handler
		 * ---------------------------------------------------- */
		private function OnOver(evt:MouseEvent):void{
//			TweenLite.to(_bg, 0.5, {autoAlpha: 1});
			_bg.visible = true;
			_txtAuthor.textColor = 0xffffff;
			_txtTitle.textColor = 0xffffff;
			_txtDate.textColor = 0xffffff;
			_arrActive.visible = true;
			_arr.visible = false;
		}
		
		private function OnOut(evt:MouseEvent):void{
//			TweenLite.to(_bg, 0.5, {autoAlpha: 0});
			_bg.visible = false;
			_txtAuthor.textColor = 0x000000;
			_txtTitle.textColor = 0x000000;
			_txtDate.textColor = 0x000000;
			_arrActive.visible = false;
			_arr.visible = true;
		}
	}
}